<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateSuppliersTable extends Migration
{
    /**
     * 数据表名称
     * @var string
     */
    private $tableName = 'suppliers';

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        // 创建数据表
        Schema::create($this->tableName, function (Blueprint $table) {
            // 数据表类型
            $table->engine = 'InnoDB';
            $table->charset = 'utf8mb4';
            $table->collation = 'utf8mb4_unicode_ci';

            // 数据表字段
            $table->bigIncrements('supplier_id')->comment('递增主键');
            $table->bigInteger('user_id', false, true)->comment('创建用户主键');
            $table->string('name', 120)->comment('名称');
            $table->string('mark', 20)->nullable()->comment('助记码');
            $table->string('avatar', 200)->nullable()->comment('头像');
            $table->string('phone', 12)->nullable()->comment('联系电话');
            $table->string('wechat_name', 20)->nullable()->comment('昵称');
            $table->string('wechat_code', 120)->nullable()->comment('微信账号');
            $table->string('description', 200)->nullable()->comment('伙伴描述');
            $table->integer('sort', false, true)->default(50)->comment('排序数值（升序）');
            $table->tinyInteger('status', false, true)->default(1)->comment('可用状态 0:停用 1:正常');
            $table->dateTime('deleted_at')->nullable()->comment('数据删除时间');
            $table->dateTime('created_at')->comment('数据创建时间');
            $table->timestamp('updated_at')->comment('数据修改时间')->default(DB::raw('CURRENT_TIMESTAMP'));

            // 数据表索引
            $table->unique('supplier_id');
            $table->index('phone');
        });
        // 设置数据表备注信息
        DB::statement("ALTER TABLE `".env('DB_PREFIX')."{$this->tableName}` COMMENT'货主表'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists($this->tableName);
    }
}
